package hl.service.impl;

import java.util.Date;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import hl.dao.BaseDao;
import hl.model.TPcOperator;
import hl.model.TStuff;
import hl.pageModel.PcOperator;
import hl.service.PcOperatorService;
import hl.util.Encrypt;

@Service("pcOperatorService")
public class PcOperatorServiceImpl implements PcOperatorService {

	private BaseDao<TPcOperator> pcOperatorDao;
	
	private BaseDao<TStuff> stuffDao;

	public BaseDao<TStuff> getStuffDao() {
		return stuffDao;
	}

	@Autowired
	public void setStuffDao(BaseDao<TStuff> stuffDao) {
		this.stuffDao = stuffDao;
	}
	
	public BaseDao<TPcOperator> getPcOperatorDao() {
		return pcOperatorDao;
	}
	
	@Autowired
	public void setPcOperatorDao(BaseDao<TPcOperator> pcOperatorDao) {
		this.pcOperatorDao = pcOperatorDao;
	}

	@Override
	public void save(PcOperator pcOperator) {
		TPcOperator tp = new TPcOperator();
		BeanUtils.copyProperties(pcOperator, tp);
		tp.setTStuff(stuffDao.get(TStuff.class, pcOperator.getPkStuff()));
		tp.setCdatetime(new Date());
		tp.setPassword(Encrypt.e(pcOperator.getPassword()));
		pcOperatorDao.save(tp);
		
	}

	@Override
	public PcOperator login(PcOperator pcOperator) {
		TPcOperator t = pcOperatorDao.get("from TPcOperator where account=? and password=?", new Object[] { pcOperator.getAccount(), Encrypt.e(pcOperator.getPassword()) });
			if (t != null)
				return pcOperator;
			else
				return null;
	}

}
